{	Problem: http://codeforces.ru/problemset/problem/36/A
	Verdict: Accepted
}
uses sysutils;
var i,n,p,r:longint; c:char;
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(n);
p:=0;
r:=-5;
for i:=1 to n do begin
  read(c);
  if c='1' then begin
    if p=0 then p:=i else
    if (p<>0) and (r=-5) then begin
      r:=i-p;
      p:=i;
    end else
    if i-p<>r then r:=-1 else p:=i;
  end;
end;
if r=-1 then write('NO') else write('YES');
end.